/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package paw.eltabique.service;

import java.util.List;
import paw.eltabique.service.interfaces.PerfilFacadeRemote;
import paw.eltabique.service.interfaces.PerfilFacadeLocal;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import paw.eltabique.domain.Perfil;

/**
 *
 * @author drakart
 */
@Stateless
public class PerfilFacade extends AbstractFacade<Perfil> implements PerfilFacadeLocal, PerfilFacadeRemote {
  @PersistenceContext(unitName = "eltabique-ejbPU")
  private EntityManager em;

  protected EntityManager getEntityManager() {
    return em;
  }

  public PerfilFacade() {
    super(Perfil.class);
  }

  @Override
  public Perfil gerPerfilByNombre(String nombre) {
    Query q = (Query) em.createQuery("SELECT p FROM Perfil p WHERE p.nombre = :NAME'");
     q.setParameter("NAME",nombre);
     List<Perfil> list = q.getResultList();
     if(list.isEmpty())
        return null;
     else
       return list.get(0);
  }

}
